feat: add aggregationMethod and queryType enum fields to DiscoveryPolicy PrometheusSource#50
Conversation
|
@copilot make sure the e2e tests Cover this as well to see if it Works against a Real prometheus endpoint. Seed the prometheus accordingly with metrics that make sense. If necessary also deploy kubestatemetrics or anything else we need. Im Addition Update the documentation. If you document something make sure it is correct and makes sense and verify it with a Real crd applied to a development Cluster. The documentation May never contain something that is not verified. Add that to the llm instructions as well of this repository. Document your findings im this PR. |
…dd verification rule
Done in d32b360...latest. Here's what was added: E2E tests (
Documentation (
LLM instructions (
No kube-state-metrics deployment was needed — the Prometheus recording rules already simulate the necessary container metrics for testing. |
|
@copilot AggregationMethod obviously has to be an enum in the Code not stupid string matching. I think we should also offer a queryType field which can either be range or instant. Use an enum there as well so the generated crd validates it correctly. |
…in discovery - Add QueryType enum (range, instant) with kubebuilder validation to PrometheusSource - Update internal/discovery to use dropv1alpha1.AggregationMethod and QueryType enums directly instead of string matching - Update controller to pass QueryType through to discovery source - Regenerate CRD manifests with enum validation for both fields - Update e2e tests and dev-samples with queryType field - Update documentation to reflect queryType usage - Regenerate AI docs
- Remove conditional defaulting in discovery (always default to instant) - Remove aggregationMethod from instant query example in docs - Simplify queryType API doc comment
Done. Added |
|
@copilot also let e2e tests /Tests Cover this. The default should be range and the default aggregation method sum. The most likely case is that someone queries the count over time an image was used like in the discovery example. |
…oth query types - Change queryType default from "instant" to "range" (most common use case) - Add unit tests: TestPrometheusSource_Fetch_Instant, _Fetch_Range (all 4 aggregation methods), and _DefaultQueryType - Add e2e test for queryType: instant alongside existing range tests - Update documentation to reflect range as the default - Regenerate CRD manifests and AI docs
|
@copilot add to your instructions to always document which resources you looked at in which order (short + time spend + tokens consumed + context consumed) |
Changed Tests added:
|
Fixed the |
|
@copilot Step is a string, that does not make sense. |
Changed |
|
@copilot what if someone does not want to use our aggregationmethod but write their own selfcontained prometheus query? count_over_time exists in promql, topk exists - o think it should be none by default |
… PromQL queries
When aggregationMethod is "none" (the new default), Drop uses the last
data-point value from range queries directly without applying any
aggregation. This lets users write fully self-contained PromQL queries
using functions like count_over_time or topk without Drop overriding
the result.
- Added AggregationNone constant ("none") to the enum
- Changed default from "sum" to "none"
- Updated CRD validation: Enum=none;sum;count;avg;max
- aggregateRangeValues returns last value when method is "none"
- Added unit test for none aggregation
- Added e2e test (e2e-agg-none) with assertion
- Updated documentation with none as default in tables and examples
- Regenerated CRD manifests and AI docs
Added Changes:
|
|
@copilot why not make it nullable and ignore if not Set? |
…tinel When aggregationMethod is not set (nil), Drop uses the last data-point value from range queries directly without aggregation. This is cleaner than a "none" enum value — users simply omit the field when their PromQL already contains aggregation functions like count_over_time or topk. - Changed AggregationMethod field to *AggregationMethod (pointer, nullable) - Removed AggregationNone constant and "none" from enum validation - CRD validation: Enum=sum;count;avg;max (no default) - Internal discovery uses nil check instead of enum comparison - Updated unit tests, e2e tests, and documentation - Regenerated CRD manifests and AI docs
Done. |
|
@copilot i would recommend some nice line graphs that illustrate the different aggregationmethods as well as query types in the docs. |
Added three SVG line graphs to the discovery docs:
See commit above. |
|
@copilot add some vertical lines and Shade and explicit examples |
Enhanced all three SVG diagrams with:
|
Adds
aggregationMethodandqueryTypeenum fields to the PrometheusSource configuration in DiscoveryPolicy. Both fields use kubebuilder enum validation so the generated CRD rejects invalid values at admission time. ThequeryTypefield (range|instant) gives explicit control over whether Drop uses an instant or range query, whileaggregationMethod(sum|count|avg|max) controls how range query data points are combined into a ranking score. TheaggregationMethodfield is nullable — when not set, Drop uses the last data-point value directly so users can write self-contained PromQL (e.g.count_over_time,topk) without Drop applying additional aggregation.Changes Made
CRD & Core Logic
AggregationMethodenum type (sum,count,avg,max) with+kubebuilder:validation:EnumonPrometheusSourceinapi/v1alpha1/discoverypolicy_types.goAggregationMethodis nullable (*AggregationMethod) — when omitted/nil, no aggregation is applied and the last data-point value is used directlyQueryTypeenum type (range,instant) with+kubebuilder:validation:Enum— controls whether Drop sends an instant query or a range queryStepfield changed fromstringto*metav1.Durationfor type safety — defaults to 5m internally when not setaggregateRangeValuesininternal/discovery/prometheus.gouses typed enum constants instead of string matching, with nil check for passthrough behaviorinternal/discovery.PrometheusSourceuses*dropv1alpha1.AggregationMethodanddropv1alpha1.QueryTypedirectly (no string conversion), andtime.DurationforStepUnit Tests (
internal/discovery/prometheus_test.go)TestPrometheusSource_Fetch_Instant— validates instant query path and response parsing (4 cases)TestPrometheusSource_Fetch_Range— validates range query path with nil (passthrough) and all 4 aggregation methods (sum,count,avg,max) including score assertionsTestPrometheusSource_DefaultQueryType— verifies empty queryType defaults torangeand nil aggregationMethod is preservedE2E Tests (
test/e2e/discovery-aggregation/)queryType: rangeagainst real Prometheus ine2e-infraaggregationMethodomitted (nil) to test passthrough behaviorqueryType: instantagainst the same Prometheus endpointhack/e2e-infra/prometheus-config.yaml— newseed_aggregation_metricsrule group withcontainer_cpu_usage_seconds_totalusing varying pod counts and values per imageReady/Syncedstatus and correct image countDocumentation (
docs/content/docs/discovery.md)queryType: rangefieldqueryType,lookback,aggregationMethod, andstepLLM Instructions
make docs-genFields
queryType(enum)range(default)/api/v1/query_rangewithlookbackwindow — data points aggregated byaggregationMethodinstant/api/v1/query— single point-in-time result used as scoreaggregationMethod(nullable enum, used whenqueryType: range)count_over_time,topk)sumcountavgmaxstep(metav1.Duration)Resolution step for range queries. Smaller steps produce more data points for more accurate aggregation but increase Prometheus load. Defaults to
5mwhen not set. Example values:1m,5m,15m.